{extend name="base" /}
{block name="css"}
<link rel="stylesheet" href="__CSS__/ztree-metro-style.css">
{/block}
{block name="body"}
<div class="layui-body">
    <!--tab标签-->
    <div class="layui-tab layui-tab-brief">
        <ul class="layui-tab-title">
            <li class=""><a href="{:url('admin/admin_user/index')}">管理员</a></li>
            <li class=""><a href="{:url('admin/admin_user/add')}">添加管理员</a></li>
            <li class="layui-this">编辑管理员</li>
        </ul>
        <div class="layui-tab-content">
            <div class="layui-tab-item layui-show">
                <form class="layui-form form-container" action="{:url('admin/admin_user/update')}" method="post">
                    <div class="layui-form-item">
                        <label class="layui-form-label">用户名</label>
                        <div class="layui-input-block">
                            <input type="text" name="username" value="{$admin_user.username}" required  lay-verify="required" placeholder="请输入用户名" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">密码</label>
                        <div class="layui-input-block">
                            <input type="password" name="password" value="" placeholder="（选填）如不修改则留空" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">重复密码</label>
                        <div class="layui-input-block">
                            <input type="password" name="confirm_password" value="" placeholder="（选填）如不修改则留空" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">所属组织机构</label>
                        <div class="layui-input-block">
                            <input type="text" value="{$admin_user.dept_name}" readonly id="dept_name" name="dept_name" onfocus="choose_dept()" value="" required lay-verify="required"  class="layui-input">
                            <input type="hidden" value="{$admin_user.dept_id}" name="dept_id" id="dept_id">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">状态</label>
                        <div class="layui-input-block">
                            <input type="radio" name="status" value="1" title="启用" {if condition="$admin_user.status==1"} checked="checked"{/if}>
                            <input type="radio" name="status" value="0" title="禁用" {if condition="$admin_user.status==0"} checked="checked"{/if}>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">所属权限组</label>
                        <div class="layui-input-block">
                            <select name="group_id" lay-verify="required">
                                {foreach name="auth_group_list" item="vo"}
                                <option value="{$vo.id}" {if condition="$admin_user.group_id==$vo.id"} selected="selected"{/if}>{$vo.title}</option>
                                {/foreach}
                            </select>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <div class="layui-input-block">
                            <input type="hidden" name="id" value="{$admin_user.id}">
                            <button class="layui-btn" lay-submit lay-filter="*">更新</button>
                            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>
{/block}

{block name="js"}
<script src="__JS__/jquery.ztree.all.min.js"></script>
{/block}

{block name="script"}
<script>
    var ztree;
    var setting = {
        check: {
            enable: false
        },
        callback: {
            onClick: zTreeOnClick
        },
        view: {
            dblClickExpand: false,
            showLine: true,
            showIcon: false,
            selectedMulti: false
        },
        data: {
            simpleData: {
                enable: true,
                idKey: "id",
                pIdKey: "pid",
                rootpid: ""
            },
            key: {
                name: "name"
            }
        }
    };
    var dept_id,dept_name;


    function zTreeOnClick(event, treeId, treeNode) {
        dept_id = treeNode.id;
        dept_name =  treeNode.name;
    }

    function choose_dept(){
        $.ajax({
            url: "{:url('admin/dept/getJson')}",
            type: "post",
            dataType: "json",
            cache: false,
            data: {},
            success: function (data) {
                layer.open({
                    type:1,
                    title:'组织机构',
                    area: ['350px', '300px'],
                    shade:0.3,
                    shadeClose:true,
                    content:'<ul id="tree" class="ztree"></ul>',
                    success:function(layerdom,index){
                        var tree = $("#tree");
                        ztree = $.fn.zTree.init(tree, setting, data);
                    },
                    btn:'确定',
                    yes:function(){
                        $('#dept_id').val(dept_id);
                        $('#dept_name').val(dept_name);
                        layer.closeAll();
                    }
                });
            }
        });
    }
</script>

{/block}